Skip to content

Prevent infinite loops in 3D track matching - #310

Open
jdkio wants to merge 1 commit into
mainfrom
jdkio/fix_xy_matcher_loop
Open

Prevent infinite loops in 3D track matching#310
jdkio wants to merge 1 commit into
mainfrom
jdkio/fix_xy_matcher_loop

Conversation

@jdkio

@jdkio jdkio commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • prevent the X/Y 3D matcher from decrementing a candidate-hit index below zero when the final hit in a view is outside the detector bounds
  • apply the same fix to the U/V(/X) matcher, which used the same unsafe loop pattern
  • recompute the loop condition before continuing after skipped hits

Failure mechanism

Both matchers walk candidate hits backward using signed indices. When an out-of-bounds hit was encountered, the code unconditionally decremented the corresponding index and immediately continued. If that hit was at index zero, the index became -1; the continue also skipped the loop-condition update. Subsequent iterations then read outside the vector and could loop indefinitely, crash, or appear nondeterministic depending on the memory contents.

This was observed in a mini-validation run of PR #301. ConvertToTMSTree.exe stayed at 100% CPU for more than 20 minutes after the final spill was sliced, versus about 200 seconds for the previous complete run. Repeated GDB samples all landed in the detector-bound checks in TrackMatching3D_XY() even though there were only two X candidates, two Y candidates, and eight hits in each current candidate. The matcher itself is unchanged by PR #301; that PR's changed hit population exposed this pre-existing bug.

The fix stops matching when an out-of-bounds hit exhausts a required view, otherwise advances safely and updates the loop condition before continuing.

Similar-code audit

The U/V(/X) matcher contained the same unguarded decrement followed by continue, so it is fixed here too. Other reverse-index loops in TMS_Reco.cpp guard decrements with index > 0 or break immediately after reaching the boundary.

Validation

  • git diff --check
  • targeted loop-control checks for an out-of-bounds hit at index zero and at a positive index
  • source audit of decrement/continue and reverse-index patterns in src/ and app/

A full build/run is not available in the local VM because the experiment ROOT/CLHEP environment is not installed. The triggering full sample can be rerun in the FNAL environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant